package com.ti.demo.controller;

import com.ti.demo.tool.AlarmTools;
import com.ti.demo.tool.WeatherTools;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestClient;
import reactor.core.publisher.Flux;

/**
 * @description: com.ti.demo.controller
 * @Author Triagen
 * @Date 2025/7/18 10:53
 */
@RestController
public class ChatController {

    @Qualifier("chatClient")
    @Autowired
    private ChatClient chatClient;

    @Autowired
    private RestClient restClient;


    // Spring AI 的短期记忆最多 20 条
    @GetMapping("/tools/actions")
    Flux<String> toolsActions(String actions) {
        return this.chatClient.prompt()
                .user(actions)
                .toolNames("getWeatherInfo")
                .toolNames("getCurrentDateTime")   // getCurrentDateTime 用于使用 DateTimeConfiguration 中配置的工具 getCurrentDateTime，可以试下注释此行，不会调用工具 getCurrentDateTime，设置的时间会出错
                .tools(new AlarmTools())
                .toolCallbacks(WeatherTools.getCityId(restClient))
                .stream()
                .content();
    }


}
